home *** CD-ROM | disk | FTP | other *** search
- #! /bin/sh
- #######################################################
- # INTRODUCTION (.notify was written by gbrown@alumni.caltech.edu )
- # ( and is in the public domain. Tabs every 4 spaces)
- #
- # This script plays a user-specified sound when mail is received.
- # The user can specify not to play sounds when
- # * he is not logged in on the console.
- # * the mail is from a mailing list or uninteresting person
- # Sounds play even when the user is not logged in, if desired.
- # The user can specify an additional sound to play when the word 'urgent'
- # appears in first 40 lines of the message (assuming the message isn't
- # from a mailing list or unintersting person in the kill list)
- #
- # This script can also be used to control the 'vacation' program, allowing
- # the user to specify a list of people NOT to notify when the user is
- # on vacation. It is a matter of courtesy to add mailing list to this
- # list, since the people in the list don't care if you are on vacation.
- #######################################################
-
- #######################################################
- # INSTALLATION
- # (0) 'chmod 707 <this file>', so that it is executable and not writable.
- # (1) Put this script somewhere permanent.
- # (2) Turn on the public sound server in "Preferences.app". You will
- # only hear sounds if the user logged in has his public sound server on.
- # If you want to hear sounds when noone is logged on, root must have his
- # public sound server turned on.
- # (3) You should customize the variables below, following the instructions.
- # (4) execute the following line, appropriately modified
- # echo '\<yourUsername>,"|<theCompletePathnameOfThisFile>"' > ~/.forward
- # where <yourUsername> is your username and
- # <theCompletePathnameOfThisFile> is the complete
- # pathname of this file.
- #######################################################
-
- #######################################################
- # CUSTOMIZATION
- # Change the variables below to reflect the
- # desired settings at your site.
- #######################################################
- username=gbrown
- # your username
- # Example: username=gbrown
-
- mailSound=~gbrown/Library/Sounds/Glenn.snd
- # the sound to play when mail arrives
- # Example: mailSound=~gbrown/Library/Sounds/Glenn.snd
-
- urgentSound=~gbrown/Library/Sounds/Urgent.snd
- # an extra sound to play if mail is has the word 'urgent' in it
- # Example: urgentSound=~gbrown/Library/Sounds/Urgent.snd
-
- silentSenders="next-icon@ RTFusers@ omniweb-l@"
- # senders whose mail will not generate sounds. This
- # is a good place to list mailing lists. Case
- # is unimporatant in this list.
- # Example: silentSenders="next-icon@ RTFusers@ omniweb-l@"
-
- playOnlyWhenOnConsole=YES
- # if you only want sounds played when you are logged onto
- # the console, this variable should be YES. Otherwise, set
- # it to anything else.
- # Example: playOnlyWhenOnConsole=YES
-
- onVacation=NO
- # Edit your ~/.vacation.msg, run 'vacation -I' in your home directory,
- # and set onVacation to YES (in that order) when you go on vacation.
- # Set it to anything else when you return from vacation.
- # 'man vacation' for more info, but DO NOT modify the .forward file
- # as the man page says. This script handles the forwarding itself.
- # Example: onVacation=NO
-
- dontTellOnVacation=${silentSenders}
- # a space delimited list of senders you don't want to send vacation
- # messages to. Mailing lists are good should be
- # listed here. Case is unimporant here. Use $silentSenders if
- # you want this list to be the same as the silentSenders list.
- # Example: dontTellOnVacation=$silentSenders
- # Example: dontTellOnVacation="next-icon@ RTFusers@ omniweb-l jerk@netcom.com"
-
- buff=/tmp/.notify.$username.buff
- senders=/tmp/.notify.$username.senders
- ifonconsole=/tmp/.notify.$username.ifonconsole
- # The above 3 variables should specify three files
- # that this script can create. They should be in a
- # directory that $username can write to. If the files
- # exist, they must be owned by $username and
- # will be destroyed.
- # Example: buff=/tmp/.notify.username.buff
- # senders=/tmp/.notify.$username.senders
- # ifonconsole=/tmp/.notify.$username.ifonconsole
-
-
- #######################################################
- # CODE
- # Do not modify any code below this point unless you
- # really know what you are doing.
- #######################################################
-
- ##########################
- # STARTUP CODE
- ##########################
-
- homeDir=~$username #the user's home directory
- # if the ifonconsole script is not installed,
- # install a copy if needed.
- #echo p=$playOnlyWhenOnConsole.
- if test ${playOnlyWhenOnConsole-YES} = YES # if we need the script
- then
- #echo checking if installed.
- # if the $ifonconsole script is not installed, install it.
- if test \! -f $ifonconsole && $ifonconsole $username /bin/false /bin/false
- then
- #echo installing
- echo '#! /bin/sh'\ > $ifonconsole
- echo '# This script has the syntax'\ >> $ifonconsole
- echo '#ifonconsole username oncommand [offcommand]'\ >> $ifonconsole
- echo '# oncommand is executed if username is logged into the'\ >> $ifonconsole
- echo '# console. offcommand is run if not. You should put '\ >> $ifonconsole
- echo '# single quotes around the oncommand and offcommand in csh'\ >> $ifonconsole
- echo '# or sh to make them single arguments. The commands'\ >> $ifonconsole
- echo '# are executed using sh.'\ >> $ifonconsole
- echo 'if (who | fgrep console) | fgrep "$1" > /dev/null 2>&1;'\ >> $ifonconsole
- echo 'then '\ >> $ifonconsole
- echo ' ($2)'\ >> $ifonconsole
- echo 'else '\ >> $ifonconsole
- echo ' ($3)'\ >> $ifonconsole
- echo 'fi '\ >> $ifonconsole
- echo 'exit 0'\ >> $ifonconsole
- chmod a-w $ifonconsole #make sure noone can change this file
- #since we will execute it
- chmod +x $ifonconsole #make the file executable
- fi
- fi
-
- # copy the first screenful of the mail message to the buffer
- # for later perusal.
- head -40 > $buff
-
- # put the lines that specify the sender into a file.
- # the To: and CC: lines are included because so messages to a mailing
- # list can also be detected.
- grep -i '^To:' $buff > $senders
- grep -i '^CC:' $buff >> $senders
- grep -i '^From:' $buff >> $senders
- #(echo; cat $buff) | grep -i '^From' >> $senders
- # From: can be on the first line causing the ^ to not match, so put a ^ at the beginning of
- # the file.
-
- ##########################
- # SOUND PLAYING CODE
- ##########################
-
- # Test for conditions that make us not want to play a sound
- for string in $silentSenders
- do
- #echo \"$string\"
- if grep -is $string < $senders
- then PLAYSOUND=NO; break; fi
- done
-
- # Play the notification sound unless sound turned off above
- if test ${PLAYSOUND-YES} = YES
- then
- if test ${playOnlyWhenOnConsole-YES} = YES
- then
- /usr/local/bin/ifonconsole gbrown /usr/bin/sndplay\ $mailSound
- else
- /usr/bin/sndplay $mailSound
- fi
- # See if the message is urgent and play sound if it is
- if grep -i 'urgent' < $buff
- then
- #echo The message is urgent.
- if test ${playOnlyWhenOnConsole-YES} = YES
- then
- /usr/local/bin/ifonconsole gbrown /usr/bin/sndplay\ $urgentSound
- else
- /usr/bin/sndplay $urgentSound
- fi
- fi
- fi
-
- ##########################
- # VACATION CODE
- ##########################
-
- #echo entering vacation code
- if test ${onVacation-NO} = YES
- then
- # Test for conditions that make us not want to play a sound and exit if such
- # conditions are found.
- for string in $dontTellOnVacation
- do
- #echo $string
- # Don't make sounds if next-icon@ is in the 'To:' or 'CC:' line.
- if grep -is $string < $buff
- then TELLONVACATION=NO; break; fi
- done
-
- if test ${TELLONVACATION-YES} = YES
- then
- #echo going to homedir
- #cd $homeDir
- #echo calling vacation program
- /usr/ucb/vacation $username < $buff
- fi
- fi
-
- ##########################
- # CLEANUP CODE
- ##########################
- rm $buff $senders
- exit 0
-
- # This file is free, in the public domain, and offered without any warrantee whatsoever.